package com.vimhe.easyimport.filter;

import com.vimhe.easyimport.config.bean.CellConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据过滤器链
 *
 * @author Vimhe
 */
public class DataFilterChain implements DataFilter {

    /**
     * 数据过滤器列表
     */
    private List<DataFilter> dataFilters = new ArrayList<>();

    /**
     * 添加数据过滤器
     *
     * @param dataFilter 数据过滤器
     * @return 数据过滤器链
     */
    public DataFilterChain addFilter(DataFilter dataFilter) {
        dataFilters.add(dataFilter);
        return this;
    }

    @Override
    public Object filter(CellConfig cellConfig, Object cellValue) {
        for (DataFilter dataFilter : dataFilters) {
            cellValue = dataFilter.filter(cellConfig, cellValue);
        }
        return cellValue;
    }

}
